package com.itmeima.entry;

import com.itmeima.bean.Subway;
import com.itmeima.controller.ManagerController;
import com.itmeima.controller.SubwayController;

import java.util.Scanner;

public class Entry {
    private static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        //运行程序,提示管理员进行登录,
        // 根据输入的工号和姓名判断是否登录成功,
        // 登录成功,进入下一步,登录失败,给出提示,结束程序
        System.out.println("---------欢迎来到：北京地铁管理系统---------");
        System.out.println("请输入您的工号：");
        String id = sc.next();
        System.out.println("请输入您的姓名：");
        String name = sc.next();
        ManagerController managerController = new ManagerController();
        managerController.login(id,name);

        SubwayController subwayController = new SubwayController();
        while (true) {
            System.out.println("-----请选择您要执行的功能：-----");
            System.out.println("-----1. 查看地铁站---2.添加地铁站---3.退出-----");
            switch (sc.nextInt()) {
                case 1:
                    //查看
                    subwayController.viewSubways();
                    break;
                case 2:
                    //添加
                    //判断输入的编号的名称是否存在，并封装。
                    Subway sub = getSubway(subwayController);
                    boolean flag = subwayController.addSubways(sub);
                    if (flag){
                        System.out.println("添加成功");
                    }else {
                        System.out.println("添加失败");
                    }
                    break;
                case 3:
                    System.out.println("感谢使用，再见！");
                    System.exit(0);
                default:
                    System.out.println("您输入的指令有误，请重新输入~");
                    break;
            }
        }
    }

    //判断编号和名称是否重复，并封装成对象返回
    private static Subway getSubway(SubwayController subwayController) {
        String subID;
        String subName;
        while (true) {
            System.out.println("请输入地铁站编号：");
            subID = sc.next();
            System.out.println("请输入地铁站名称：");
            subName= sc.next();
            boolean flag = subwayController.judge(subID,subName);
            if (!flag) {
                break;
            }
            System.out.println("请重新输入！");
        }

        System.out.println("请输入地铁所属路线：");
        String route = sc.next();
        Subway sub = new Subway(subID,subName,route);
        return sub;
    }
}
